$(function() {
	var imageuploader = document.getElementById('imageuploader');
	var previewer = document.getElementById('previewer');
	imageuploader.onchange = function() {
		var selectedFile = this.files[0];
		var reader = new FileReader();
		reader.onload = function() {
			previewer.src = reader.result;
		}
		reader.readAsDataURL(selectedFile);
	}
	
	$('#username').on('blur',function(event) {
		var $self = $(this)
		$.post('./check.do',{username: $self.val()},function(data){
			if(data.ok === 0){
				$self.closest('.form-group').addClass('has-success has-feedback');
				$self.after('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
			}else{
				$self.closest('.form-group').addClass('has-error has-feedback');
				$self.after('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
			}
		})
	})
	
	$('#username').on('focus',function(event){
		var $self = $(this)
		$.post('./check.do',{username: $self.val()},function(data){
			if(data.ok === 0){
				$self.closest('.form-group').removeClass('has-success has-feedback');
	        	$self.next('span').remove();
			}else{
				$self.closest('.form-group').removeClass('has-error has-feedback');
	        	$self.next('span').remove();
			}
		})
	})
	
	
//	$('#vcode').on('blur',function(event) {
//		var $self = $(this)
//		$.post('./check.do',{username: $self.val()},function(data){
//			if(data.ok === 2){
//				$self.closest('.form-group').addClass('has-success has-feedback');
//				$self.after('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
//			}else{
//				$self.closest('.form-group').addClass('has-error has-feedback');
//				$self.after('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
//			}
//		})
//	})
//	
//	$('#vcode').on('focus',function(event){
//		var $self = $(this)
//		$.post('./check.do',{username: $self.val()},function(data){
//			if(data.ok === 2){
//				$self.closest('.form-group').removeClass('has-success has-feedback');
//	        	$self.next('span').remove();
//			}else{
//				$self.closest('.form-group').removeClass('has-error has-feedback');
//	        	$self.next('span').remove();
//			}
//		})
//	})
})